package net.huashitong.supervision.task.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;
import net.huashitong.supervision.task.dao.CopeToDao;
import net.huashitong.supervision.task.entity.CopeTo;
import net.huashitong.supervision.task.entity.TaskMain;
import net.huashitong.supervision.task.filter.TaskMainFilter;
import net.huashitong.supervision.task.util.HolidayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * Created with IntelliJ IDEA.
 * User: ling
 * Date: 2019/8/19
 * Time: 18:07
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Service
public class CopeToService extends StringPKService<CopeTo> {
@Autowired
private CopeToDao copeToDao;
@Autowired
private SysTableService tableService;
    @Override
    protected BaseDao<CopeTo, String> getDao() {
        return copeToDao;
    }

    @Override
    protected void beforeSave(CopeTo obj) {
        obj.setSysId(tableService.updateMaxSysId("t_cope_to",null));
    }



    public void save(CopeTo copeTo, String userId){
        Date date = new Date();
        String date1 = HolidayUtils.sdf1.format(date);
        String time = HolidayUtils.sdf2.format(date);
        copeTo.setSysId(tableService.updateMaxSysId("t_cope_to",null));
        copeTo.setCreateUser(userId);
        copeTo.setUpdUser(userId);
        copeTo.setCreateDate(date1);
        copeTo.setCreateTime(time);
        copeTo.setUpdDate(date1);
        copeTo.setUpdTime(time);
        getDao().save(copeTo);
    }
    public List<TaskMain> queryUnDone(TaskMainFilter filter) {

        return copeToDao.queryUnDone(filter);
    }

    public List<CopeTo> queryByleaderIdAndTaskMainId(String userId,String taskMainId) {
        return copeToDao.queryByleaderIdAndTaskMainId(userId,taskMainId);
    }

    public List<TaskMain> queryNowDone(TaskMainFilter filter) {
        return copeToDao.queryNowDone(filter);
    }

    public List<TaskMain> queryDone(TaskMainFilter filter) {
        return copeToDao.queryDone(filter);
    }
    public List<TaskMain> queryAllDone(TaskMainFilter filter) {
        return copeToDao.queryAllDone(filter);
    }

    public List<CopeTo> getByTaskMainId(String sysId) {

        return copeToDao.getByTaskMainId(sysId);
    }
    public List<CopeTo> getByTaskMainIdDel(String sysId) {

        return copeToDao.getByTaskMainIdDel(sysId);
    }
}
